﻿function ajax(method,url,data,success){
    var xhr=null;
    /**兼容处理ie6以下*/
    /**
    if(window.XMLHttpRequest){
        xhr =new XMLHttpRequest();
    }else{
        xhr=new ActiveXObject('Microsoft.XMLHTTP');
    }
    */
    /**异常处理兼容 */
    try{
        xhr=new XMLHttpRequest();
    }catch(e){
        xhr=new ActiveXObject('Microsoft.XMLHTTP');
    }

    xhr.open(method,url,true);
    /**get,post方法*/
    if(method=='get' && data){
        url+='?'+data;
    }
    xhr.send();
    if(method=='get'){
        xhr.send();
    }else{
        xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
        xhr.send(data);
    }

    xhr.onreadystatechange=function(){
        if(xhr.readyState==4){
            if(xhr.readyState==200){
            success && success(xhr.responseText);
            }
        }else{
            alert('Error'+xhr.status)
        }
    }
}

